package com.yuanda.wordhot.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.yuanda.wordhot.entity.ResultEntity;
import com.yuanda.wordhot.entity.RoleEntity;
import com.yuanda.wordhot.repository.RoleRepository;

@Service
public class RoleService {
	@Autowired
	private RoleRepository roleRepository;

	@Transactional
	public void deleteRole(int roleId) {
		roleRepository.remove(roleRepository.get(roleId));
	}
	@Transactional
	public void updateRole(RoleEntity role) {
		roleRepository.update(role);
	}
	@Transactional
	public void addRole(RoleEntity role) {
		roleRepository.add(role);
	}
	
	public ResultEntity getAllRoles(int start, int count) {
		List<RoleEntity> rows = roleRepository.getAllRoles(start, count);
		long total = roleRepository.getTotalRoles();
		ResultEntity result = new ResultEntity(total, rows);
		return result;
	}
	
	public List<RoleEntity> getAllRoles(){
		return roleRepository.getAllRoles(0, 0);
	}
}
